define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order/index' + location.search,
                    add_url: 'order/order/add',
                    edit_url: 'order/order/edit',
                    del_url: 'order/order/del',
                    multi_url: 'order/order/multi',
                    table: 'order',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_sn', title: __('Order_sn')},
                        {field: 'phone', title: __('Phone')},
                        // {field: 'member_id', title: __('Member_id')},
                        {field: 'member_name', title: __('Member_name')},
                        // {field: 'rent_id', title: __('Rent_id')},
                        {field: 'rent_name', title: __('Rent_name')},
                        {field: 'card_number', title: __('Card_number')},
                        {field: 'type', title: __('Type'), searchList: {"1":__('Type 1'),"2":__('Type 2')}, formatter: Table.api.formatter.normal},
                        {field: 'rent_price', title: __('Rent_price')},
                        {field: 'if_rent', title: __('If_rent'), searchList: {"0":__('If_rent 0'),"1":__('If_rent 1')}, formatter: Table.api.formatter.normal},
                        {field: 'cash_price', title: __('Cash_price')},
                        {field: 'if_cash', title: __('If_cash'), searchList: {"0":__('If_cash 0'),"1":__('If_cash 1')}, formatter: Table.api.formatter.normal},
                        {field: 'total_price', title: __('Total_price')},
                        // {field: 'company_id', title: __('Company_id')},
                        {field: 'company_name', title: __('Company_name')},
                        // {field: 'shareholder_id', title: __('Shareholder_id')},
                        {field: 'shareholder_name', title: __('Shareholder_name')},
                        {field: 'station_id', title: __('Station_id')},
                        {field: 'order_status', title: __('Order_status'), searchList: {"0":__('Order_status 0'),"1":__('Order_status 1'),"2":__('Order_status 2'),"3":__('Order_status 3'),"4":__('Order_status 4'),"5":__('Order_status 5'),"6":__('Order_status 6'),"7":__('Order_status 7')}, formatter: Table.api.formatter.status},
                        {field: 'payment_code', title: __('Payment_code'), searchList: {"0":__('Payment_code 0'),"1":__('Payment_code 1'),"2":__('Payment_code 2')}, formatter: Table.api.formatter.normal},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'start_time', title: __('Start_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'cash_time', title: __('Cash_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'return_time', title: __('Return_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'expire_time', title: __('Expire_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'if_deferred', title: __('If_deferred'), searchList: {"0":__('If_deferred 0'),"1":__('If_deferred 1')}, formatter: Table.api.formatter.normal},
                        {field: 'cash_deferred', title: __('Cash_deferred'), searchList: {"0":__('Cash_deferred 0'),"1":__('Cash_deferred 1')}, formatter: Table.api.formatter.normal},
                        // {field: 'sell_id', title: __('Sell_id')},
                        {field: 'sell_phone', title: __('Sell_phone')},
                        {field: 'sell_name', title: __('Sell_name')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});